<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        main {
            box-sizing: border-box;
            background-color: azure;
            width: 600px;
            margin: 50px auto;
            height: 400px;
            border-top: 1px solid transparent;
        }

        main div {
            margin: 50px auto;
            width: 300px;
            height: 300px;
        }

        main input {
            border: gainsboro solid 1px;
            border-radius: 15px;
            outline: none;
            margin: 20px auto;
            box-sizing: border-box;
            padding-left: 20px;
            width: 300px;
            height: 40px;
            margin-bottom: 20px;
        }

        main div .inp {

            background-color: blue;
            color: white;
        }

        main p {
            color: blue;
            float: right;
        }
    </style>
</head>

<body>
    <main>
        <div>
            <input type="text" placeholder="手机号/用户名/邮箱">
            <input type="password" placeholder="密码">
            <p>忘记密码?</p>
            <input class="inp" type="button" value="登录">
        </div>
    </main>
</body>

</html>
<script src="promise-ajax.js"></script>
<script>
    var inputss = document.querySelectorAll('main>div>input')
    inputss[2].onclick = function () {
        if (inputss[0].value && inputss[1].value) {
            if (/^\d{4}$/.test(inputss[1].value)) {
                ajax('get', 'https://yantianfeng.com/api/login', { username: inputss[0].value, password: inputss[1].value }).then((data) => {
                    if (data.status == 200) {
                        alert(data.msg);
                    } else {
                        alert('登陆失败!');
                    }
                })
            } else {
                alert('请输入正确手机号/密码')
            }
        }
        else {
            alert('亲，用户名或密码不能为空哟！')
        }
    }
</script>